package com.lishe.lishe.lishe.module.me.pickerView.adapter;
/**
 * @Author ：程序员小冰
 *
 * @新浪微博 ：http://weibo.com/mcxiaobing
 *
 * @GitHub: https://github.com/QQ986945193
 *
 * @CSDN博客: http://blog.csdn.net/qq_21376985
 *
 * @OsChina空间: https://my.oschina.net/mcxiaobing
 *
 */

/**
 * Numeric Wheel adapter.
 */
public class NumericWheelAdapter implements WheelAdapter {

	/** The default min value */
	public static final int DEFAULT_MAX_VALUE = 9;

	/** The default max value */
	private static final int DEFAULT_MIN_VALUE = 0;

	// Values
	private int minValue;
	private int maxValue;

    private String unit;

	/**
	 * Default constructor
	 */
	public NumericWheelAdapter() {
		this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE);
	}

    /**
     * Default constructor
     */
    public NumericWheelAdapter(String unit) {
        this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE);
        this.unit = unit;
    }

	/**
	 * Constructor
	 * @param minValue the wheel min value
	 * @param maxValue the wheel max value
	 */
	public NumericWheelAdapter(int minValue, int maxValue) {
		this.minValue = minValue;
		this.maxValue = maxValue;
	}

    /**
     * Constructor
     * @param minValue the wheel min value
     * @param maxValue the wheel max value
     */
    public NumericWheelAdapter(int minValue, int maxValue,String unit) {
        this.minValue = minValue;
        this.maxValue = maxValue;
        this.unit = unit;
    }

	@Override
	public Object getItem(int index) {
        String temp = "";
        if(unit!=null)
        {
            temp = unit;
        }
		if (index >= 0 && index < getItemsCount()) {
			int value = minValue + index;
			return value + temp;
		}
		return 0 + temp;
	}

	@Override
	public int getItemsCount() {
		return maxValue - minValue + 1;
	}

	@Override
	public int indexOf(Object o){
		//return (int)o - minValue;

        String v = o.toString();
        if(this.unit!=null && !this.unit.equals(""))
        {
            v = v.replace(this.unit,"");
        }

        int t = Integer.parseInt(v);
        return t - minValue;
	}
}
